﻿using B.S.Outsourcing.ErrorCode;
using B.S.Outsourcing.Infatructrue;
using B.S.Outsourcing.Writer.Api.Application.Command.OutSourOrderModel;
using MediatR;

namespace B.S.Outsourcing.Writer.Api.Application.CommandHandler.OutSourOrderModel
{
    public class DeleteOutSourOrderCommandHandler : IRequestHandler<DeleteOutSourOrderCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<CreateOutSourOrderCommand> baseRepository;
        private readonly DBHelper1 dBHelper;

        public DeleteOutSourOrderCommandHandler(IBaseRepository<CreateOutSourOrderCommand> baseRepository, DBHelper1 dBHelper)
        {
            this.baseRepository = baseRepository;
            this.dBHelper = dBHelper;
        }

        public async Task<ApiResult<int>> Handle(DeleteOutSourOrderCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var sql = $"update OutsourcingOrderModel set IsDelete=1 where id={request.Id} ";
            var str = dBHelper.NonQuery(sql);
            if (str>0)
            {
                result.Code = ApiEnums.成功;
                result.Message = "成功";
                result.Data = str;
            }
            else
            {
                result.Code = ApiEnums.成功;
                result.Message = "成功";
                result.Data = str;
            }
            return await  Task.FromResult(result);
        }
    }
}
